<?php
namespace App\Admin\Exporter\Merchant;

use Encore\Admin\Grid;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
use Maatwebsite\Excel\Concerns\WithHeadings;

class MerchantExpoter extends ExcelExporter implements WithMapping, WithStrictNullComparison, WithHeadings
{

    protected $fileName = "网点月度统计.xlsx";

    public function headings(): array
    {

        if (!empty($this->columns)) {

            return array_values(array_unique($this->columns));
        }

        return parent::headings();
    }
    // 设置需要从库中检索出的字段
    protected $columns = [
        'network_name' => '网点名称',
        'start_time' => '结算开始时间',
        'end_time' => '结算结束时间',
        'order_number' => '订单数',
        'turnover_amount' => '成交额',
        'created_at' => '统计时间',
    ];
    // 设置映射字段
    public function map($row): array
    {
        return [
            $row->network_name,
            $row->start_time,
            $row->end_time,
            $row->order_number,
            $row->turnover_amount,
            $row->created_at,
        ];
    }
}
